<!-- 首页 -->
<template>
	<view class="page">
		<view class="card-title">相册</view>
		<view class="card-box">
			<view class="no-text" v-if="user.albums == '' || user.albums == null">暂未上传</view>
			<view class="image-box" v-else>
				<u-album :urls="albumList" :locks="user.imageLock" @preAd="preAd"></u-album>
			</view>
		</view>
		
		<view class="card-title">职业</view>
		<view class="card-box">
			<view class="no-text" v-if="user.profession == null">暂未填写</view>
			<view v-else>{{user.profession}}</view>
		</view>
		
		<view class="card-title">兴趣爱好</view>
		<view class="card-box">
			<view class="no-text" v-if="user.hobby == null">暂未填写</view>
			<view v-else>{{user.hobby}}</view>
		</view>
		
		<view class="card-title">自我介绍</view>
		<view class="card-box">
			<view class="no-text" v-if="user.introduce == null">暂未填写</view>
			<view v-else>{{user.introduce}}</view>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		albumList: {
			// 动态数据
			type: Array,
			required: true,
			default: function() {
				return [];
			}
		},
		user: {
			type: Object,
			required: false,
			default: function() {
				return {};
			}
		},
	},
	data() {
		return {
			
		};
	},
	mounted() {
		this.init();
	},
	methods: {
		init() {
			
		},
		preAd(run) {
			var _this = this;
			
			uni.login({
				provider: 'weixin',
				success: function(loginRes) {
					var code = loginRes.code;
					_this.$u.get('/system/config/getAdValue',{
						code: code,
						appId: _this.website.appId
					}).then(res => {
						uni.login({
							provider: 'weixin',
							success: function(e) {
								_this.openImg(e.code, res.data, res.adId, run);
							},
							fail: function() {
								
							}
						});
					});
				},
				fail: function() {
					
				}
			});
		},
		openImg(code,config,adId,run) {
			var adNum = uni.getStorageSync("adNum");
			if(adNum > 0){
				adNum = adNum - 1;
				uni.setStorageSync("adNum", adNum);
				run(true);
				return;
			}
			
			var adFlag = false;
			var content = "观看广告并点击广告下方绿色按钮后再返回，即可解锁资源";
			if("0" == config){
				run(true);
				return;
			}else if("1" == config){
				// 需要点击广告
				adFlag = false;
			}else if("2" == config){
				// 不需要点击广告
				adFlag = true;
				content = "观看广告后，即可解锁资源";
			}else if("3" == config){
				// 需要转发好友
				content = "今日观看广告次数已用完，请转发好友或者群聊，即可解锁5次资源";
			}
			
			var _this = this;
			uni.showModal({
			  title: '提示',
			  content: content,
			  success: (res) => {
			    if (res.confirm) {
					if("3" == config){
						uni.setStorageSync("adClick", false);
						uni.$off('test');
						uni.$on('test', function(res){
							if(res){
								uni.setStorageSync("adNum", 4);
								_this.$store.commit('setCash', false);
								_this.addAdLog(code, "03");
								uni.$off('test');
								run(true);
							}else{
								uni.showModal({
								  title: '您没有转发成功',
								  content: '您没有转发成功，请重新来过',
								  showCancel: false,
								  success: (res) => {
									  run(false);
								  }
								});
							}
						});
						_this.$store.commit('setCash', true);
						return;
					}
					//加载激励广告
					_this.$utils.videoAdInit(adId);
					// 在适合的场景显示插屏广告
					_this.$utils.videoAdShow()
					.then((res) => {
					  if (res) {
						var adClik = uni.getStorageSync("adClick");
						console.log("点击广告"+adClik);
						if(adClik || adFlag){
							if(adClik){
								_this.addAdLog(code, "02");
							}else{
								_this.addAdLog(code, "01");
							}
							run(true);
						}else{
							_this.addAdLog(code, "01");
							uni.showModal({
							  title: '您没有点击绿色按钮',
							  content: '您没有点击绿色按钮，请重新来过',
							  success: (res) => {
								  run(false);
							  }
							});
						}
					  } else {
						console.log('广告提前退出')
						_this.addAdLog(code, "00");
						run(false);
					  }
					})
					.catch((err) => {
						console.log('广告加载失败')
						run(false);
					});  
			    }
			  }
			});
		},
		addAdLog(code, action) {
			this.$u.post('/wq/ad/add',{
				adAction: action,
				appId: this.website.appId,
				code: code,
			}).then(res => {
				
			});
		},
	}
};
</script>
<style lang="scss" scoped>
	.page {
		padding: 15px;
	}
	.card-title {
		margin-bottom: 10px;
		font-size: 28rpx;
	}
	.card-box {
		background-color: #fff;
		padding: 30rpx;
		border-radius: 20rpx;
		font-size: 26rpx;
		margin-bottom: 20px;
		white-space: pre-wrap;
		min-height: 240rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.image-box {
		width: 100%;
	}
	.no-text {
		color: #b4adad;
	}
</style>
